package daoFramework;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class dbConn {

	
	public Connection getConnection() throws SQLException {
		Connection conn = null;
		
		String host = "jdbc:mysql://localhost/gespatrim";
		String username = "app";
		String pass = "pantufa";
		
			try {
				Class.forName("com.mysql.jdbc.Driver");
				conn = DriverManager.getConnection(host,username,pass);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		return conn;
	}
	
	public void close(Statement stmt) {
		if (stmt == null) return;
		
		try {
			stmt.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void close(Connection conn) {
		if (conn == null) return;
		
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void close(ResultSet rs) {
		if (rs == null) return;
		
		try {
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void closeAll(Statement stmt, Connection conn) {
		close(stmt);
		close(conn);
	}

	public void closeAll(Statement stmt, Connection conn, ResultSet rs) {
		closeAll(stmt, conn);
		close(rs);
	}


}
